﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Grishko.DataTier;
using OutdoorLib.BaseEntity.Dictionary;
using OutdoorLib.BaseEntity.Agency;
using OutdoorLib.BaseEntity.Infrastructure;

namespace OutdoorLib.BaseEntity.Provider
{
    /// <summary>
    /// Класс представляющий в системе провайдера услуг
    /// </summary>
    public class ProviderEntity:EntitySingle ,ISqlSignature 
    {
        private SettingInfo _Settings = new ProviderEntity.ProviderSettingInfo();
        private const string key = "Provider";
        
        public class ProviderSettingInfo : SettingInfo,IFileSignature 
        {
            public string Directory
            {
                get
                {
                    return "Provider";
                }
            }
            public  string FileName
            {
                get
                {
                    return "Provider.xml";
                }
            }
        }
        
        public static void Reset()
        {
            CacheTools.ResetSessionCache (key );
        }
        
        public static ProviderEntity GetProvider()
        {
            
                if (!CacheTools.IsSessionCacheObject(key ))
                {
                    ProviderEntity p = new ProviderEntity();
                    p.Load();
                    CacheTools.SetSessionCacheObject(key , p);
                    return p;
                }

                return (ProviderEntity)CacheTools.GetSessionCacheObect(key );

    }

        public override void Save()
        {            
            base.Update();
            Reset ();
        }     
        
        public override string ID
        {
            get
            {
                return "Provider";
            }            
        }

        private FilterList _FilterList = new FilterList();
        
        /// <summary>
        /// список общих фиьтров всех агенств
        /// </summary>
        public FilterList FilterList
        {
            get { return _FilterList; }
            set { _FilterList = value; }

        }


        public SettingInfo Settings { get { return _Settings; } }


        #region ISqlSignature Members

        public virtual string SaveProcedure
        {
            get { return "SaveProvider"; }
        }

        public virtual string DeleteProcedure
        {
            get { return ""; }
        }

        public virtual string LoadProcedure
        {
            get { return "LoadProvider"; }
        }
        

        #endregion

        
    }
    
    

}
